<template >
    <table class="table-bordered" border="1">
        <tr>
            <td>用户名</td>
            <td><input v-model="index.name" type="text"></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input v-model="index.pwd" type="password"></td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" @click="repasd" value="注册" class="btn btn-success"></td>
        </tr>
    </table>
    </template>
    <script setup lang="ts">
    import { ref } from 'vue';
    import axois from 'axios';
    import {useRouter} from 'vue-router';
    const router=useRouter();
    const index = ref({
        name:"",
        pwd:""
    });
    const repasd=()=>{
        axois({
            url:"https://localhost:44366/api/Drom/UserRegister",
            data:{
                UserName:index.value.name,
                Password:index.value.pwd    
            },
            method:"post"
        })
        .then(res=>{
            if(res.data==2){
                alert('用户名已存在')
                return
            }
            if(res.data>0){
                alert("注册成功");
                router.push('/Login')
            }else{
                alert("注册失败");
            }
        })
        .catch(err=>{
            console.log(err);
        })
    }
    </script>